﻿using System.Drawing;
using System.Media;
using System.Windows.Forms;

namespace Marmat.Forms
{
    public class Prompt
    {

        /// <summary>
        /// 音频文件的地址
        /// </summary>
        private static string AudioFileName;

        /// <summary>
        /// 弹出提示窗口。
        /// </summary>
        /// <param name="content">提示的内容</param>
        /// <param name="title">提示的标题</param>
        /// <param name="interval">计划关闭的时间</param>
        public static void Show(string content, string title = null, int interval = 3000)
        {
            Show(null, content, title, interval);
        }

        /// <summary>
        /// 弹出提示窗口。
        /// </summary>
        /// <param name="owner">任何实现 System.Windows.Forms.IWin32Window 并表示将拥有此窗体的顶级窗口的对象。</param>
        /// <param name="content">提示的内容</param>
        /// <param name="title">提示的标题</param>
        /// <param name="interval">计划关闭的时间</param>
        public static void Show(IWin32Window owner, string content, string title = null, int interval = 3000)
        {
            var frm = new PromptForm();
            frm.Text = title; // 设置窗口标题
            frm.MemoEdit1.EditValue = content; // 设置窗口文本内容
            int width = SystemInformation.WorkingArea.Width; // 获取屏幕的宽度
            int height = SystemInformation.WorkingArea.Height; // 获取屏幕的高度

            // 设置窗体初始位置
            frm.StartPosition = FormStartPosition.Manual;
            var location = new Point(width - frm.Width, height - 10);
            frm.Location = location;
            frm.Show(owner);

            // 播放音频文件
            if (System.IO.File.Exists(AudioFileName) == true) // 如果找到音频文件的话，播放该文件
            {
                SoundPlayer player = new SoundPlayer();
                player.SoundLocation = AudioFileName;
                player.PlaySync(); //UI线程同步播放
            }

            // 动画效果
            for (int i = 1, loopTo = frm.Height; i <= loopTo; i += 2)
            {
                frm.SetBounds(width - frm.Width, height - i, frm.Width, frm.Height);
            }
            frm.Start(interval);
        }
    }
}